import {
  getPage,
  getImage
} from '../../utils/config';
import {
  http,
  promisify,
  $empty,
  $toast,
  Validate
} from '../../utils/utils';
import api from '../../utils/api';
import wxApi from '../../utils/wxApi';
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: '',
  },

  /**
   * 快递单号
   */
  messageInput(e) {
    this.setData({
      messageInputError: '',
      content: e.detail,
    });
  },


  /**
   * 提交表单--网络请求
   */
  tousuForm(e) {
    
    Validate.check(this, this.expressValidate, e.detail.value, (res) => {
      if (res) {
        const {
          type,
          shopid,
          userId,
          shopname,
          content,
          title
        } = this.data;
        let params = {
          action: 'tousu',
          shopid:shopid,
          userid: userId,
          content: content,
          type:type,
          title:title
        }

        http.post(api.default, { data: params }).then((res) => {
          if (res.data.code == 0) {
            wxApi.navigateBack(1);
            $toast("提交成功");
          }
          else{
            $toast(res.data.errmsg);
          }
        });
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    //获取携带参数
    if (JSON.stringify(options) != '{}') {

      app.getLogin().then((res) => {
        const {
          user
        } = res.data;
        this.setData({
          shopid: options.id,
          shopname: options.name,
          userId: user.user_id,
          type:options.type,
          title:options.title
        });
      });
    }

    //获取验证规则
    Validate.rules('#message', (res) => {
      this.expressValidate = res;
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})